import 'package:flutter/material.dart';
import '../../common/ScreenAdaper.dart';
import './Show.dart';
import './Content.dart';
import './Comment.dart';

class GoodsPage extends StatefulWidget {
  Map arguments;
  GoodsPage({Key key,this.arguments}) : super(key: key);
  _GoodsPageState createState() => _GoodsPageState();
}

class _GoodsPageState extends State<GoodsPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print(Text("${widget.arguments['sId']}"));
  }
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar: AppBar(
          title: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                width: S.width(400),
                child: TabBar(
                    indicatorSize: TabBarIndicatorSize.label, // 与文字等宽
                    tabs: [
                      Tab(text:'商品'),
                      Tab(text:'详情'),
                      Tab(text:'评价'),
                    ]
                ),
              )
            ],
          ),
          actions: <Widget>[
            _leftButton(),
          ],
        ),
        body: Stack(
          children: <Widget>[
            TabBarView(children: [
              ShowPage(),
              ContentPage(),
              CommentPage(),
            ]),
            Positioned(
              width: S.width(750), // ScreenAdaper.dart 中设置的设备宽度
              height: S.width(80),
              bottom: 0,
              child: Container(
                color: Colors.red,
                child: Text(
                    "底部"
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 右侧按钮
  IconButton _leftButton(){
    return IconButton(icon: Icon(Icons.more_horiz), onPressed: (){
      showMenu(
          context: context,
          position: RelativeRect.fromLTRB(S.width(200), 76, 10, 0),
          items: [
            PopupMenuItem(
              child: GestureDetector(
                child: Row(
                  children: <Widget>[
                    Icon(Icons.home),
                    Container(
                      padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
                      child: Text("首页"),
                    )
                  ],
                ),
                onTap: (){
                  Navigator.pop(context);
                  Navigator.pushNamed(context, "/index");
                },
              ),
            ),
            PopupMenuItem(
              child: GestureDetector(
                child: Row(
                  children: <Widget>[
                    Icon(Icons.search),
                    Container(
                      padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
                      child: Text("搜索"),
                    )
                  ],
                ),
                onTap: (){
                  Navigator.pop(context);
                  Navigator.pushNamed(context, "/search");
                },
              ),
            )
          ]
      );
    });
  }
}